package com.baor.controller;

import com.baor.service.LeaveService;
import com.baor.service.LeaveTypeService;
import com.baor.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.config.annotation.web.reactive.EnableWebFluxSecurity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/Leave")
public class LeaveController {

    @Autowired
    private LeaveService leaveService;
    private LeaveTypeService leaveTypeSevice;

    @RequestMapping("/LeaveList")
    public AjaxResult<?> LeaveList(@RequestBody Map<String, Object> param) {
        int pageIndex = (int) param.get("pageIndex");
        int pageSize = (int) param.get("pageSize");
        int num = (pageIndex - 1) * pageSize;
        param.put("pageIndex", num);
        return leaveService.LeaveList(param);
    }

    @RequestMapping("/AddLeave")
    public AjaxResult<?> AddLeave(@RequestBody Map<String, Object> param) {
        return leaveService.addLeave(param);
    }

    @RequestMapping("/LeaveInfo")
    public AjaxResult<?> LeaveInfo(@RequestBody Map<String,Object> params) {
        int leaveId = Integer.parseInt(params.get("leaveId").toString());
        return this.leaveService.LeaveInfo(leaveId);
    }

    @RequestMapping("/AddLeaveInfo")
    public AjaxResult<?> addLeaveInfo() {
        return this.leaveService.addLeaveInfo();
    }

    @RequestMapping("/UpdateLeaveInfo")
    public AjaxResult<?> updateLeave(@RequestBody Map<String, Object> param) {
        return this.leaveService.updateLeaveInfo(param);
    }

    @RequestMapping("/DeleteLeaveInfo")
    public AjaxResult<?> deleteLeave(@RequestBody Map<String, Object> param) {
        return this.leaveService.deleteLeaveInfo(param);
    }
}
